<?php

use Biz\service\trade\Cart as sCart;
use Doraemon\cache\Queue;
use Doraemon\service\MemberRoleTag;

/**
 * @deprecated
 */
class AddToCartAction extends ActionPlugin
{
    const USER_LEVEL = self::LEVEL_VISITOR;

    public function main()
    {
        $skuId = $this->getRequest()->getPost('sku_id');
        $buyNum = $this->getRequest()->getPost('buy_num');
        $version = version_compare($this->appVersion, '4.6.5', '>=');
        if ($version || $this->appType == self::APPTYPE_PARAGRAPH_MINIPROGRAM) {
            sCart::addToCart(($this->uid > 0) ? $this->uid : $this->vid, $skuId, $buyNum, $this->appType);
        } else {
            throw new \Exception('操作失败，请更新到最新版本APP');
        }


        Queue::insertQueue('queue/UserRole/SaveRoleTag', [
            'vid' => $this->vid,//vid
            'tag_id' => MemberRoleTag::ROLE_TAG_CART,//分群id
            'value' => '2',//对应的值
            'uid' => $this->uid,
        ], Queue::QUEUE_ROLE_TAG);

        $this->setSuccess();
    }
}